﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using EZCRS.HCMS.DataAcl;
using EZCRS.HCMS.Bll.baseinfo;

namespace EZCRS.HCMS.Web.manage.news
{
    public partial class news_more : ManageBase
    {

        //记录数量
        int iRecordCount = 0;
        //总页数
        int iPageCount = 0;
        //存放数据返回给客户端
        ArrayList arrRecord = new ArrayList();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CheckModule(4);

                ClientScript.RegisterClientScriptBlock(this.GetType(),"ids", "<script language=javascript>var gid='"+BasGroupId.ToString()+"';var pid='"+BasHotelId.ToString()+"';</script>");
                Titlepage1.initlabnew = "<a href=\"news_add.aspx\"><img src=\"../../image/new.gif\" border=0></a> ";
                AjaxPro.Utility.RegisterTypeForAjax(typeof(EZCRS.HCMS.Web.manage.news.news_more));
                form1.Attributes["onkeydown"] = "if (event.keyCode==13){return Page_Load('First')}";
                BtnSearch.Attributes.Add("onclick", "javascript:Page_Load('Search');return false;");
           
            }
             
        }
        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public ArrayList Getrecord(int pageindex, string sqlstr,string gid,string pid)
        {
            try
            {
                string[] arrsql = sqlstr.Split('|');
                string strwhere = " gid="+gid.ToString()+" and pid="+pid.ToString()+" ";
                if (arrsql[0].Trim() != "")
                {
                    strwhere += " and newtopics  like '%" + arrsql[0] + "%'";
                }
                BllNews AN = new BllNews();
                DataSet ds = AN.News_List(CFun.PageSize, pageindex, strwhere);
                iRecordCount = Convert.ToInt32((ds.Tables[1].Rows[0]["mm"]));
                iPageCount = (iRecordCount / CFun.PageSize);
                if (iRecordCount % CFun.PageSize > 0)
                {
                    iPageCount++;
                }
                StringBuilder strTable = new StringBuilder();
                strTable.Append("<table border=\"0\" cellpadding=\"1\" cellspacing=\"1\" width=\"100%\"><tr class=\"title1\" height=\"26\"><td width=\"5%\" style=\"color: white;\">" + Resources.Site.LabNo + "</td><td width=\"20%\" style=\"color: white;\">" + Resources.Site.LabNewsTopics + "</td><td width=\"55%\" style=\"color: white;\">" + Resources.Site.LabNewsKey + "</td><td width=\"20%\" style=\"color: white;\">" + Resources.Site.LabEdit+ "</td></tr>");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    for (int row = 0; row < ds.Tables[0].Rows.Count; row++)
                    {
                        strTable.Append("<tr");
                        if (row % 2 == 0)
                        {
                            strTable.Append(" class='line-odd'");
                        }
                        else
                        {
                            strTable.Append(" class='line-even'");
                        }
                        strTable.Append(" onmouseover=\"currentcolor=this.style.backgroundColor;this.style.backgroundColor='#B9CEEA';\"");
                        strTable.Append(" onmouseout=\"this.style.backgroundColor=currentcolor;\"");
                        strTable.Append(">");
                        string sNo = "";
                        if (((pageindex - 1) * CFun.PageSize + row + 1) < 10)
                        {
                            sNo = "0" + Convert.ToString(row + 1);
                        }
                        else
                        {
                            sNo = Convert.ToString((pageindex - 1) * CFun.PageSize + row + 1);
                        }
                        strTable.Append("<td><div align=\"center\">");
                        strTable.Append(sNo.ToString());
                        strTable.Append("</div></td>");
                        strTable.Append("<td><div align=\"center\">");
                        strTable.Append(ds.Tables[0].Rows[row]["newtopics"].ToString());
                        strTable.Append("</div></td>");
                        strTable.Append("<td><div align=\"center\">");
                        strTable.Append(ds.Tables[0].Rows[row]["newkey"].ToString());
                        strTable.Append("</div></td>");
                        strTable.Append("<td><div align=\"center\">");
                        strTable.Append("<a href='news_add.aspx?mid=" + ds.Tables[0].Rows[row]["newid"].ToString() + "'><img src=\"../../Image/modify.gif\" alt=\""+Resources.Site.LabEdit+"\" style=\"border:0;\" /></a>");
                        strTable.Append("</div></td></tr>");
                    }
                }
                else
                {
                    strTable.Append("<tr height=\"35\" class=\"line-odd\"><td colspan=\"6\" align=\"center\">"+Resources.Site.LabNoData+"</td></tr>");
                }
                strTable.Append("</table>");
                //将表格放入arraylist
                arrRecord.Add(strTable.ToString());
                //将总页数放入arraylist
                arrRecord.Add(iPageCount.ToString() == "0" ? "1" : iPageCount.ToString());
                //将总记录数放入arraylist
                arrRecord.Add(iRecordCount.ToString());
            }
            catch
            {

            }
            return arrRecord;
        }

    }
}
